package cn.cloudmenu.android.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import cn.cloudmenu.android.R;

public class Profile extends Activity {

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profile);
		System.out.println("Profile webview this.findViewById(R.id.profile_webview) = "
				+ this.findViewById(R.id.profile_webview));
		WebView webView = (WebView) this.findViewById(R.id.profile_webview);
		String href = getResources().getString(R.string.profile_jsp);
		System.out.println("Profile.onCreate() = " + href);
		TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		href = href + tm.getDeviceId();
		System.out.println("Profile.onCreate() href = " + href);
		webView.loadUrl(href);
		// webView.loadUrl("http://jquerymobile.com/demos/1.0a4.1/");

		WebSettings webSettings = webView.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webSettings.setSaveFormData(false);
		webSettings.setSavePassword(false);
		webSettings.setSupportZoom(false);
		webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

		// myjs是自己定义的，供javascript访问的接口
		// this is necessary for "alert()" to work
		webView.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onConsoleMessage(String message, int lineNumber, String sourceID) {
				// System.out.println("MyApplication : "+ message +
				// " -- From line "+ lineNumber + " of " + sourceID);
				super.onConsoleMessage(message, lineNumber, sourceID);
			}
		});
		webView.setFocusable(true);
		webView.requestFocus(View.FOCUS_DOWN);
	}

	public void close(View view) {
		Intent intent = new Intent(this, CloudMenu.class);
		this.startActivity(intent);
	}

	public void neverShowAgain(View view) {
		saveSettings(true);
		close(view);
	}

	private void saveSettings(boolean neverShowAgain) {
		SharedPreferences settings = this.getSharedPreferences(this.getClass().getName(), MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("neverShowAgain", neverShowAgain);
		editor.commit();
	}
}